/**
 * Created by Administrator on 2017/10/20.
 */
/**
 *构造器
 */
var socketHandler={
    query:null,
    lay:null,
    socketIo:null,
    uMask:null,
    use_dom:null,
    search_type:null,
    search_friend_name:null,
    search_group_name:null,
    search_user_list:null,
    search_group_list:null,
    unread_message:null,
    frined_list:null,
    group_list:null,
    chat_list:null,
    underscore:null,
    chatEditer:null,
    ChatTalkUser:null,
    mineInfo:null,
    chatFriendTalkList:[],
    is_min_type:true,
    chat_group_select:null,
    chat_load_index:null,
    group_chat_now:null,
    dialog_index:null,
    dialog_options:null,
    counter:0, //当前的消息计数器
    nowMessage:null,
    config:{
        socketUri:'http://192.168.0.164',
        socketPort:9501,
        tips_second:3000,
        socketEvents:{
            emitEvents:{
                login_emit:'login.interface',
                register_emit:'register.interface',
                refresh_emit:'refresh.interface',
                chat_emit:'chat.interface',
                ping_package_emit:'ping.response.interface',
                ping_package_refresh_emit:'hart.beat.ping.interface',
                search_friend_emit:'search.friend.interface',
                add_friend_emit:'add.friend.interface',
                accept_add_friend_request_emit:'is.accept.friend.add.request.interface',
                search_group_emit:'search.group.interface',//这个模糊搜索
                apply_join_group_emit:'user.join.group.interface',
                agree_join_group_emit:'agree.join.group.interface',
                user_add_category_emit:'add.category.from.user.interface',
                user_change_category_emit:'user.change.category.interface',
                unread_single_messag_emit:'single.unread.message.interface',
                monitor_read_message_emit:'monitor.read.message.interface',
                sync_store_unread_emit:'sync.store.message.interface',
                create_group_emit:'create.group.interface',
                get_group_members_emit:'get.group.members.interface',
                group_chat_emit:'group.chat.interface',
            },
            onEvents:{
                connect:'connect',
                currentMark:'send.current.mark',
                disconnect:'disconnect',
                errorInfo:'error.info',
                userList:'send.chat.user.list',
                loginSuccess:'send.login.success',
                registerSuccess:'send.register.success',
                chatSuccess:'send.chat.success',
                chatAcceptSuccess:'send.chat.accept.Message',
                pingPackage:'send.ping.package',
                systemMessagePerson:'send.system.message.push',
                systemMessageGroup:'send.system.message.group.push',
                searchFriendSuccess:'send.search.friend,success',
                addFriendReturnBack:'send.add.friend.return.back',
                addFriendAccept:'send.add.friend.accept',
                addFriendAcceptSuccess:'send.add.friend.accept.success',
                searchGroupExists:'send.search.group.exists.success',
                applyJoinGroupRequest:'send.apply.join.group.request',
                returnBackApplyJoinGroupSuccess:'send.return.back.apply.join.group.success',
                acceptApplyJoinGroupSuccess:'send.accept.apply.join.group.success',
                acceptApplyJoinGroupClientSuccess:'send.accept.apply.join.group.client.success',
                addCategoryFromUserSuccess:'send.add.category.from.user.success',
                userChangeCategorySuccess:'send.user.change.category.success',
                unreadMessageSingleSuccess:'send.unread.message.single.success',
                listUnreadMessageSuccess:'send.list.unread.message.success',
                refreshUserListSuccess:'send.refresh.user.list.success',
                refreshGroupListSuccess:'send.refresh.group.list.success',
                broadcastTestSuccess:'send.broadcast.test.success',
                createGroupSuccess:'send.create.group.success',
                RequstGroupUserListSuccess:'send.request.group.user.list.success',
                GroupUserListSuccess:'send.group.user.list.success',
                acceptGroupMessageSuccess:'send.accept.group.message.success',//群聊消息
            }
        },
        pageDom:[],//此选项还是需要外面的配置
    },
    commFunctions:{
        emptyValue:function(value){
            if(typeof value==='object'){
                return 0===value.length
            }
            if((value==='' || value===null) || (value===undefined  || value==='undefined'))
            {
                return true
            }
            return false;
        },
        inArray: function (value,object) {
            var flag            =   false;
            if(typeof object !=='object'){return false;}
            for(var i in  object){
                if(value==object[i]){
                    flag        =   true;
                }
            }
            return flag;
        },
        ArrayKey:function(value,object){
            if(typeof object !=='object'){return false;}
            var returnKey       =   '';
            for(var key in  object){
                if(value==object[key]){
                    returnKey    = key;
                }
            }
            return ''==returnKey?false:returnKey;
        },
        deleteArrayValue:function(delValue,object){
            if(typeof object !=='object'){return false;}
            var new_array   =   [];
            for(var delKey in object){
                if(delValue!==object[delKey]){
                    new_array.push(object[delKey])
                }
            }
            return new_array;
        },
        setStoreInfo:function(key,value){
            try {
                if(!window.localStorage)
                {
                  throw '抱歉当您使用的浏览器不支持存储请更换浏览器！'
                }
                localStorage.setItem(key,value);
            }catch (e) {
                /*this.lay.msg(e,{time:this.tips_second,icon:2});*/
                return false;
            }
        },
        getStoreInfo:function(key){
            try{
                if(!window.localStorage)
                {
                    throw '抱歉当您使用的浏览器不支持存储请更换浏览器！'
                }
                var storeData=localStorage.getItem(key);
                if(0===storeData){
                    throw '抱歉key：'+key+'没有存储任何的值！';
                }
                return storeData;
            }catch (e){
                /*this.lay.msg(e,{time:this.tips_second,icon:2});*/
                return false;
            }
        },
        parseJson:function(JsonValue){
            try{
                if(typeof JsonValue !=='string'){
                    throw  ('服务器抱歉数据不合法！');
                }
               var      json_decode_data    =    $.parseJSON(JsonValue);
               return   json_decode_data;
            }catch (e){
                /*this.lay.msg(e,{time:this.tips_second,icon:2});*/
                return false;
            }
        },
        requestQueryParam:function(queryObj){
            try {
                if(typeof queryObj !=='object' || 0== queryObj.length)
                {
                    throw ('抱歉参数不合法');
                }
                var queryString             =   '';
                for(var i in queryObj)
                {
                    queryString+=i+"="+queryObj[i]+'&';
                }

                queryString         =    queryString.split("&");
                queryString.length  =    queryString.length-1;
                return     queryString.join('&')
            }catch (e) {
                return false;
            }
        }
    },
    otherUri:{
        registerJumpUri:""
    },
    otherEvent:{},
    _init:function(dom,uri,otherDom ,callback){
        try {
            this.query              =   $;
            this.lay                =   layer;
            if(typeof callback==='function'){
                this.underscore    = callback.call();
            }
            this.config.pageDom    =    this.query.merge(this.config.pageDom,dom);
            this.otherUri          =    this.query.extend(this.otherUri,uri);
            this.otherEvent        =    this.query.extend(this.otherEvents,otherDom);
            this._initSocketIo().registerEvents().addEvents().otherEvents().GetMessageNum();
        }catch (e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    _initSocketIo:function() {
        try {
            //实例化当前的socket实例
            this.socketIo = io(this.config.socketUri + (this.config.socketPort !== null ? ":" + this.config.socketPort : ''));
            if(!this.socketIo)
            {
                throw  ('抱歉socket链接错误！');
            }
            return this;
        }catch (e){
            this.lay.msg(e, {time: this.config.tips_second, icon:2});
            return false;
        }
    },
    registerEvents:function() {
        try{
            var that            =   this;  //es6就不会出现跨域的问题
            //链接的时候触发
            this.socketIo.on(this.config.socketEvents.onEvents.connect,function(){that.onConnect()});
            //链接服务端会马上触发该监听函数用来接受不socket链接的标识（唯一）
            this.socketIo.on(this.config.socketEvents.onEvents.currentMark,function(message){that.onCurrentMark(message)});
            //服务器连接断开说明服务器主动断开事件
            this.socketIo.on(this.config.socketEvents.onEvents.disconnect,function(message){that.onDisconnect(message)});
            //接收服务器发送的错误信息接口
            this.socketIo.on(this.config.socketEvents.onEvents.errorInfo,function(message){that.onErrorInfo(message)});
            //服务器返回登录成功数据接口
            this.socketIo.on(this.config.socketEvents.onEvents.loginSuccess,function(message){that.onLoginSuccess(message)});
            //服务器返回注册成功数据接口
            this.socketIo.on(this.config.socketEvents.onEvents.registerSuccess,function(message){that.onRegisterSuccess(message)});
            //服务器ping包接口十秒未响应会自动剔除该socket链接 以及当前链接响应服务器ping package 接口
            this.socketIo.on(this.config.socketEvents.onEvents.pingPackage,function(message){that.onPingPackage(message)});
            //服务器刷新当前的在线列表人数和列表数据
            this.socketIo.on(this.config.socketEvents.onEvents.userList,function(message){that.onRefreshChatUserList(message)});
            //服务器收索朋友存在成功回调
            this.socketIo.on(this.config.socketEvents.onEvents.searchFriendSuccess,function(message){that.onSearchFriendSuccess(message)});
            //添加好友返回信息接口
            this.socketIo.on(this.config.socketEvents.onEvents.addFriendReturnBack,function(message){that.onAddFriendReturnBack(message)});
            //添加好友对方接受您的添加好友
            this.socketIo.on(this.config.socketEvents.onEvents.addFriendAccept,function(message){that.onAddFriendAccept(message)});
            //接受好友添加请求同意或者拒绝好友的添加
            this.socketIo.on(this.config.socketEvents.onEvents.addFriendAcceptSuccess,function(message){that.onAddFriendAcceptSuccess(message)});
            //搜索组服务器返回成功接口
            this.socketIo.on(this.config.socketEvents.onEvents.searchGroupExists,function(message){that.onSearchGroupExistsSuccess(message);});
            //服务器推送加入组的接口
            this.socketIo.on(this.config.socketEvents.onEvents.applyJoinGroupRequest,function(message){that.onApplyJoinGroupRequest(message)});
            //申请加入组成功回调接口
            this.socketIo.on(this.config.socketEvents.onEvents.returnBackApplyJoinGroupSuccess, function (message) {that.onReturnBackApplyJoinGroupSuccess(message)});
            //群主同意加入群组反馈消息接口
            this.socketIo.on(this.config.socketEvents.onEvents.acceptApplyJoinGroupSuccess,function(message){that.onAcceptApplyJoinGroupSuccess(message)});
            //客户端加入群组消息反馈接口
            this.socketIo.on(this.config.socketEvents.onEvents.acceptApplyJoinGroupClientSuccess,function(message){that.onAcceptApplyJoinGroupClientSuccess(message)});
            //服务器添加分类成功返回接口
            this.socketIo.on(this.config.socketEvents.onEvents.addCategoryFromUserSuccess,function(message){that.onAddCategoryFromUserSuccess(message);});
            //自己把某个好友换到某个自定义分组里面成功接口
            this.socketIo.on(this.config.socketEvents.onEvents.userChangeCategorySuccess,function(message){that.OnUserChangeCategorySuccess(message);});
            //未读系统消息接口
            this.socketIo.on(this.config.socketEvents.onEvents.unreadMessageSingleSuccess,function(message){that.OnUnreadMessageSingleSuccess(message);});
            //监听未读系统消息列表
            this.socketIo.on(this.config.socketEvents.onEvents.listUnreadMessageSuccess,function(message){that.onListUnreadMessageSuccess(message);}),
            //获取用户列表接口
            this.socketIo.on(this.config.socketEvents.onEvents.refreshUserListSuccess,function(message){that.onRefreshUserListSuccess(message)});
            //获取当前的用户所在群组接口
            this.socketIo.on(this.config.socketEvents.onEvents.refreshGroupListSuccess,function(message){that.onRefreshGroupListSuccess(message)});
            //测试广播
            this.socketIo.on(this.config.socketEvents.onEvents.broadcastTestSuccess,function(message){that.onDroadcastTestSuccess(message);})
            //监听好友消息接口 point to point 
            this.socketIo.on(this.config.socketEvents.onEvents.chatAcceptSuccess,function(message){that.onChatAcceptSuccess(message);});
            //箭筒发送消息成功的接口
            this.socketIo.on(this.config.socketEvents.onEvents.chatSuccess,function(message){that.onChatSuccess(message);});
            //添加组成功回调接口
            this.socketIo.on(this.config.socketEvents.onEvents.createGroupSuccess,function(message){that.onCreateGroupSuccess(message);});
            //监听当前的请求组列表成功接口
            this.socketIo.on(this.config.socketEvents.onEvents.RequstGroupUserListSuccess,function(message){that.onRequstGroupUserListSuccess(message);});
            //监听打开群聊天接口
            this.socketIo.on(this.config.socketEvents.onEvents.GroupUserListSuccess,function(message){that.onGroupUserListSuccess(message);});
            //接收群聊消息接口
            this.socketIo.on(this.config.socketEvents.onEvents.acceptGroupMessageSuccess,function(message){that.onAcceptGroupMessageSuccess(message);});
            return this;
        }catch (e){
            /*this.lay.msg(e, {time: this.config.tips_second, icon:2});*/
            return false;
        }
    },
    addEvents:function(){
        try{
            var that                =   this;
            for(var i= 0 in this.config.pageDom)
            {
                //注册    事件
                this.query('body').on('click',"."+that.config.pageDom[i],function(){
                    that.distributionEvents(this);
                });
            }
            return this;
        }catch (e){
            /*this.lay.msg(e, {time: this.config.tips_second, icon:2});*/
            return false;
        }
    },
    distributionEvents:function(click_events){
        try{
            var that                =   this; //不够简化 switch 不能以变量的形式存在
            this.query(this.config.pageDom).each(function(index,value){
                if(true===that.query(click_events).hasClass(value))
                {
                    switch (value)
                    {
                        case 'chat_login':that.emitLoginInterface(click_events);
                            break;
                        case 'chat_register':that.commonJumpRegister(click_events);
                            break;
                        case 'real_register':that.emitRegisterInterface(click_events);
                            break;
                        case 'back_login':that.commonJumpLogin(click_events);
                            break;
                        case 'send_message':that.emitChatInterface(click_events);
                            break;
                        case 'add_friend':that.emitAddFriend(click_events);
                            break;
                        case 'apply_join_group':that.emitJoinGroup(click_events);
                            break;
                        case 'system_message_num':that.emitUnreadSingleMessag(click_events);
                            break;
                        case 'agree_refuse':that.emitRefuseAgree(click_events);
                            break;
                        case 'chat_client': that.emitChatClientOpen(click_events);
                           break;
                    }
                }
            });
        }catch (e){
            /*this.lay.msg(e, {time: this.config.tips_second, icon:2});*/
            return false;
        }
    },
    otherEvents:function(){
        var that            =   this;
        this.query('.chat_page').on('click','.'+this.otherEvent.chat_add_friend,function(){
            that.search_type        =that.otherEvent.chat_add_friend;
            that.searchFriendGroupShow(this);
        });
        this.query('.chat_page').on('click','.'+this.otherEvent.chat_add_group,function(){
            that.search_type        =that.otherEvent.chat_add_group;
            that.searchFriendGroupShow(this);
        });
        this.query('.chat_page').on('click','.'+this.otherEvent.chat_search_button,function() {
            that.searchDis(this);
        });

        this.query('.chat_page').on('click','.'+this.otherEvent.chat_tb_switch,function(){
           that.TabSwitch(this,that.otherEvent.chat_tb_switch) ; 
        });
        this.query('body').on('click','.'+this.otherEvent.chat_friend_talk_switch,function(){
            that.emitChatClientOpen(this);
        });
        this.query('body').on('click','.'+this.otherEvent.chat_create_group,function(){
            that.emitCreateGroup();
        });
        this.query('body').on('click','.'+this.otherEvent.chat_group_chat,function(event){
            that.emitGroupChat(this);
        });
        this.query('body').on('click','.'+this.otherEvent.chat_swiper_dom,function(event){
            that.commonSwiperAction(this);
        });
        this.query('body').on('click','.'+this.otherEvent.chat_send_group,function(event){
            that.emitCahtGroupMessage(this);
        });
        return this;
    },
    onConnect:function(msg){ //链接时触发
        console.log('socket 链接已经链接!')
    },
    onCurrentMark:function(msg){  //初始化当前的uMask
         try {
             var message       =    this.query.parseJSON(msg);
             this.uMask        =    message.uMask;
             if(this.commFunctions.getStoreInfo('userInfo'))
             {
                var chat_user_info_data= this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo'));
                console.log(chat_user_info_data);
                this.mineInfo   = chat_user_info_data;
                if( 
                    (
                        false===this.commFunctions.emptyValue(chat_user_info_data.name)
                        &&
                        false===this.commFunctions.emptyValue(chat_user_info_data.id)
                    )
                )
                {
                    var queryString             =this.commFunctions.requestQueryParam({
                        refresh_name:chat_user_info_data.name,
                        refresh_id:chat_user_info_data.id,
                        refresh_uMask:this.uMask
                    });
                    //保证刷新的是新的链接
                    this.socketIo.emit(this.config.socketEvents.emitEvents.refresh_emit,queryString);
                    this.query('.'+this.otherEvent.chat_change_name).html(chat_user_info_data.name);
                }
             }
         }catch (e){
             /*this.lay.msg('抱歉uMask组件错误！', {time: this.config.tips_second, icon:2});*/
             return false;
         }
    },
    onErrorInfo:function(msg){
        try {
            var message             =   this.query.parseJSON(msg);
            if(0===message.length){
                throw ('抱歉服务器返回错误信息异常！');
            }
            this.uMask              =   message.uMask;
            this.lay.msg(message.msg,{time: this.config.tips_second, icon:2});
        }catch (e){
            this.lay.msg(e, {time: this.config.tips_second, icon:2});
            return false;
        }
    },
    onDisconnect:function(msg){
        console.debug(msg);
        //服务器主动断开连接
      /*  this.lay.msg(msg,{icon:2,time:this.config.tips_second});*/
    },
    onLoginSuccess:function(msg){
        try{
            var login_success_data      =   this.commFunctions.parseJson(msg);
            if(0===login_success_data.length){
                throw  ('抱歉服务器返回数据格式错误！');
            }
            if(
                (true===this.commFunctions.emptyValue(login_success_data.name)
                ||
                true===this.commFunctions.emptyValue(login_success_data.id)
                )
                ||
                true===this.commFunctions.emptyValue(login_success_data.uMask)
            ){
                throw ('抱歉服务器返回数据不合法!');
            }
            this.uMask                  =   login_success_data.uMask;
            //储存当前的登录信息
            this.commFunctions.setStoreInfo('userInfo',msg);
            //登录成功直接进入chat界面
            window.location.href        =   this.otherUri.loginJumpChatUri;
        }catch (e){
           /* this.lay.msg(e, {time: this.config.tips_second, icon:2});*/
            return false;
        }
    },
    onRegisterSuccess:function(msg){
        try{
            var register_success_data      =   this.commFunctions.parseJson(msg);
            console.log(register_success_data);
            if(0===register_success_data.length){
                throw  ('抱歉服务器返回数据格式错误！');
            }
            if(
                (true===this.commFunctions.emptyValue(register_success_data.name)
                    ||
                    true===this.commFunctions.emptyValue(register_success_data.id)
                )
                ||
                true===this.commFunctions.emptyValue(register_success_data.uMask)
            ){
                throw ('抱歉服务器返回数据不合法!');
            }
            this.uMask              =   register_success_data.uMask;
            //储存当前注册信息
            this.commFunctions.setStoreInfo('userInfo',msg);
        }catch (e){
            this.lay.msg(e, {time: this.config.tips_second, icon:2});
            return false;
        }
    },
    onPingPackage:function(msg){
        try {
             if(!this.commFunctions.getStoreInfo('userInfo')){
                return false;
             }
             var ping_info      = this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo'));
             if(false==ping_info){
                return false;
             }
             var queryString  = JSON.stringify({
                 ping_user_id:ping_info.id,
                 ping_user_name:ping_info.name,
                 ping_uMask:this.uMask,
             });
             this.socketIo.emit(this.config.socketEvents.emitEvents.ping_package_emit,queryString);
        }catch (e){
            this.lay.msg(e,{time: this.config.tips_second, icon:2});
            return false;
        }
    },
    onRefreshChatUserList:function(msg){
        try{
            console.log(msg);
            var that                   =    this;
            var user_group_list        =    this.commFunctions.parseJson(msg);
            var html                   =    '';
            //因为没有如vue 或者angular js 的MVVM 所以不能进行热更新只能在每次下线的时候就像前端客户端推送当前的用户和用户所属组的
            for(var i in user_group_list)
            {
                var personal        =   user_group_list[i];
                if(true===personal.online)
                {
                   html         +="<li class='online' draggable='true'><a href='javascript:void(0)'>"+personal.name+"</a></li>"
                }
                if(false===personal.online)
                {
                    html        +="<li class='no-online' draggable='true' mark-down='"+i+"'><a  href='javascript:void(0)'>"+personal.name+"</a></li>";
                }
            }
            this.query('.single_list').html(html);
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    onSearchFriendSuccess:function(msg){
      try {

          var search_friend_success = this.commFunctions.parseJson(msg);
          var search_friend_data = search_friend_success[0];
          var layOptions = {
              type: 1,
              area: ['25%', '50%'],
              title: '小小为您找到了下面的一些人',
              shade: 0.6,
              maxamin: true,
              anim: 2
          };
          var out_wrapper =this.query('<div class="chat_search_box">  <div class="chat_search_title"></div> <div class="chat_search_content"> <ul class="search_line site-doc-icon"> </ul> </div></div>');
          var search_user_list  =   '';
          this.search_user_list =   search_friend_data.data;
          this.query(search_friend_data.data).each(function(){
              search_user_list+=   '<li class="chat_search_result">\
                  <div class="search_line_box">\
                  <div class="search_line_wrapper">\
                  <div class="chat_line_interval"></div>\
                  <div class="search_line_img">\
                  <img src="/static/images/images.png" class="layui-circle">\
                  </div>\
                  <div class="search_line_name"><span>'+this.name+'</span><span>'+(this.sex==0?"女":"男")+'</span></div>\
                  </div>\
                  </div>\
                  <div class="search_line_btn">\
                  <button class="layui-btn layui-btn-small add_friend">申请加好友</button>\
                  </div>\
                  </li>';
          });
          this.query(out_wrapper).find('.search_line').html(search_user_list);
          layOptions.content        =this.query(out_wrapper)[0].outerHTML;
          this.commonDialog(layOptions);
      }catch (e){
          this.lay.msg(e,{time:this.config.tips_second,icon:2});
          return false;
      }
    },
    onAddFriendReturnBack:function(msg){
        try {
           var return_back_message  = this.commFunctions.parseJson(msg);
            if(0==return_back_message.length)
            {
                throw ('返回数据错误！');
            }
            this.lay.tips(return_back_message.message,this.use_dom,{tips:[2,'#158F08'],time:4000});
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
        }
    },
    onAddFriendAccept:function(msg){
        try{
            //接受好友请求消息以弹层的方式加以通知或者是这个是个人在线的请求弹层
            var accept_friend_message   =   this.commFunctions.parseJson(msg);
            console.log(msg);
            if(0==accept_friend_message.length)
            {
                throw ('数据不合法');
            }
            var layOptions          ={
                type:1,
                area:['500px','300px'],
                title:accept_friend_message.message,
                shade:0.6,
                maxamin:true,
                anim:-1,
                btn:['同意请求','决绝请求']
            };
            layOptions.content="<div><span>"+accept_friend_message.from_chat_name+"</span>请求添加好友 </div>";
            var that                    =   this;
            this.commonDialog(layOptions);
            //由于dialog不支持取消时间所以手动添加一个取消事件
            this.query(".layui-layer-btn1").click(function(){
                that.emitAcceptAddFriendRequest(accept_friend_message,'disagree',that);
            });
            this.query('.layui-layer-btn0').click(function () {
                that.emitAcceptAddFriendRequest(accept_friend_message,'agree',that);
            });
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    onAddFriendAcceptSuccess:function(msg){
        try {
            var add_friend_accept_success_message = this.commFunctions.parseJson(msg);
            if(true===this.commFunctions.emptyValue(add_friend_accept_success_message.type))
            {
                throw ('抱歉当前数据非法！');
            }
            this.lay.msg(add_friend_accept_success_message.message,{time:this.config.tips_second,icon:1});
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    onSearchGroupExistsSuccess:function(msg){
        try {
            var group_data_list     =   this.commFunctions.parseJson(msg);
            if(0===group_data_list.data.length)
            {
                throw ('抱歉没有找到你想要加入的组！');
            }
            var layOptions = {
                type: 1,
                area: ['25%', '50%'],
                title: '小小为您以下群组',
                shade: 0.6,
                maxamin: true,
                anim: 2
            };
            var output_wrapper =this.query('<div class="chat_search_box">  <div class="chat_search_title"></div> <div class="chat_search_content"> <ul class="search_line site-doc-icon"> </ul> </div></div>');
            this.search_group_list = group_data_list.data;
            var  search_group_list  ='';
            this.query(group_data_list.data).each(function(){
                search_group_list+=   '<li class="chat_search_result">\
                  <div class="search_line_box">\
                  <div class="search_line_wrapper">\
                  <div class="chat_line_interval"></div>\
                  <div class="search_line_img">\
                  <img src="/static/images/images.png" class="layui-circle">\
                  </div>\
                  <div class="search_line_name"><span>'+this.group_name+'</span></div>\
                  </div>\
                  </div>\
                  <div class="search_line_btn">\
                  <button class="layui-btn layui-btn-small apply_join_group">申请加入组</button>\
                  </div>\
                  </li>';
            });
            this.query(output_wrapper).find('.search_line').html(search_group_list);
            layOptions.content        =this.query(output_wrapper)[0].outerHTML;
            this.commonDialog(layOptions);
        }catch (e){
            this.lay.msg(e,{time:this.tips_second,icon:2});
            return false;
        }
    },
    onApplyJoinGroupRequest:function(msg){
        try{
               var that                         =   this;
               var apply_join_group_request     =   this.commFunctions.parseJson(msg);
               if(0===apply_join_group_request.length)
               {
                   throw ('抱歉数据不合法');
               }
               var layOptions     ={
                   type:1,
                   area:['500px','300px'],
                   title:apply_join_group_request.message,
                   shade:0.6,
                   maxamin:true,
                   anim:-1,
                   btn:['同意请求','决绝请求']
               };
               layOptions.content="<div><span>"+apply_join_group_request.message+"</span></div>";
               //先关闭当前打开的所有dialog
               this.commonDialog(layOptions);
               //分配事件
               this.query(".layui-layer-btn1").click(function(){
                    that.emitJoinGroupRequestIsAgree(apply_join_group_request,'disagree');
               });
               this.query('.layui-layer-btn0').click(function () {
                   that.emitJoinGroupRequestIsAgree(apply_join_group_request,'agree');
               })
        }catch (e) {
            this.lay.msg(e,{icon:2,time:this.tips_second});
            return false;
        }
    },
    onReturnBackApplyJoinGroupSuccess:function(msg) {
        try {
            var join_group_apply_group = this.commFunctions.parseJson(msg);
            if(0===join_group_apply_group.length)
            {
                throw ('抱歉数据合法');
            }
            this.lay.tips(join_group_apply_group.message,this.query(this.use_dom),{tips:[2,'#158F08'],time:4000});
        }catch (e) {
            this.lay.msg(e,{icon:2,time:this.tips_second});
            return false;
        }
    },
    onAcceptApplyJoinGroupSuccess:function(msg){
        try{
            var accept_apply_message= this.commFunctions.parseJson(msg);
            this.lay.msg(accept_apply_message.message,{icon:1,time:4000})
        }catch (e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    onAcceptApplyJoinGroupClientSuccess:function(msg){
        try {
           var accept_client_apply_message= this.commFunctions.parseJson(msg);
           this.lay.msg(accept_client_apply_message.message,{icon:1,time:4000})
        }catch (e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    onAddCategoryFromUserSuccess:function(msg){
        var category_add_data   =   this.commFunctions.parseJson(msg);
        console.log(category_add_data);
    },
    OnUserChangeCategorySuccess:function(msg){
        var user_change_category_data   =   this.commFunctions.parseJson(msg);
    },
    OnUnreadMessageSingleSuccess:function(msg){
        try{
            //啃爹呀 找了1个小时原来是前端的问题
            var unread_message_single_data  =   this.commFunctions.parseJson(msg);
            //考虑是直接加还是怎么。。点击查看之后那么直接变为0或者空
            this.query('.is_show_message').text(unread_message_single_data.countNum);
            this.GetMessageNum();
       }catch(e){
        this.lay.msg(e,{icon:2,time:this.config.tips_second});
        return false;
       }
    },
    onListUnreadMessageSuccess:function(msg){
        try{
                var list_unread_data = this.commFunctions.parseJson(msg);
                 var layOptions = {
                        type: 1,
                        area: ['35%', '50%'],
                        title: '消息盒子',
                        shade: 0.6,
                        maxamin: true,
                        anim: 2
                    };
                    var output_wrapper =this.query('<div class="chat_search_box">  <div class="chat_search_title"></div> <div class="chat_search_content"> <ul class="search_line site-doc-icon"> </ul> </div></div>');
                    var  unread_message_list  ='';
                    this.query(list_unread_data.data).each(function(){
                        var btn_type   ='';
                        switch(this.message_type){
                            case 3:btn_type='<button mark-name='+this.from_chat_name+' mark-class='+this.from_chat_id+' class="layui-btn layui-btn-small agree_refuse" mark-shit="agree_add_freind">同意请求</button><button class="layui-btn layui-btn-primary layui-btn-small  agree_refuse" mark-shit="refuse_add_friend">拒绝请求</button>';
                            break;
                            case 4:btn_type='<button mark-name='+this.from_chat_name+' mark-class='+this.from_chat_id+' mark-group='+this.what_group+' class="layui-btn layui-btn-small agree_refuse" mark-shit="agree_join_group">同意申请</button><button class="layui-btn layui-btn-primary layui-btn-small agree_refuse" mark-shit="refuse_join_group">拒绝申请</button>';
                            break;
                        };
                        unread_message_list+=   '<li class="chat_search_result">\
                          <div class="search_line_box">\
                          <div class="search_line_wrapper">\
                          <div class="chat_line_interval"></div>\
                          <div class="search_line_img">\
                          <img src="/static/images/images.png" class="layui-circle">\
                          </div>\
                          <div class="search_line_name"><span>'+this.from_chat_name+'</span><span>'+(this.sex?"男":"女")+'</span></div>\
                          <div class="search_result_message">'+this.message+'</div>\
                          </div>\
                          </div>\
                          <div class="search_line_btn">\
                          '+btn_type+'\
                          </div>\
                          </li>';
                    });
                    this.query(output_wrapper).find('.search_line').html(unread_message_list);
                    layOptions.content        =this.query(output_wrapper)[0].outerHTML;
                    this.commonDialog(layOptions);
         }catch(e){
           this.lay.msg(e,{icon:2,time:this.config.tips_second})
            return false;
         }
    },
    onRefreshUserListSuccess:function(msg){
        try{
            var that            = this;
            var friend_list     = this.commFunctions.parseJson(msg);
            if(0===friend_list.length)
            {
                throw ('抱歉你还没有任何好友！。。');
            }
            this.frined_list   = friend_list;
            var text           = '';
            for(var i in friend_list){
                text+='<div class="main_title">\
                    <div></div>\
                    '+i+'\
                </div>';
                this.query(friend_list[i]).each(function(index){
                    text+='<div class="main_list">\
                        <div class="img_box chat_client" mark-name='+this.friend_id+'><img src="/static/images/images.png" width="500" height="500"/></div>\
                            <div class="inf_box">\
                            <div class="inf_list"><span>'+this.friend_name+'</span><span class="message_un_box">'+(this.unread==0?"":this.unread)+'</span></div>\
                                <div class="inf_list color">'+(this.friend_sex?"男":"女")+'</div>\
                            </div>\
                        </div>';
                });
            }
            this.query('.chat_friend_cate_list').html(text);
        }catch(e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    onRefreshGroupListSuccess:function(msg){
        try{
              var refresh_group_list   =   this.commFunctions.parseJson(msg);
              this.group_list          =    refresh_group_list;
              var html                 =  '';
              if(refresh_group_list.length===0){
                this.query('.chat_group_cate_list').html(' <div class="main_title">\
                <div></div>\
                 还没加入任何的群组喔\
                </div>')
                throw ('抱歉你还没加入群组赶快搜索加入吧！');
              }
              this.query(refresh_group_list).each(function(index){
                html+='<div   class="main_title group_chat"  data-group='+this.group_id+' >\
                        <div></div>\
                        <span>'+this.group_name+'</span><span>'+this.member_total+'人</span>\
                        <span class="chat_msg_num"></span>\
                    </div>';
              });
              this.query('.chat_group_cate_list').html(html);
       }catch(e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
       }
    },
    onDroadcastTestSuccess:function(msg){
        console.debug(msg);
    },
    onChatAcceptSuccess:function(msg){
        try{
            console.debug(msg);
            this.commonPushFriendMessage(msg,false,false);
       }catch(e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
       }
    },
    onPushMessage:function(){
        //>>只解决了当前的用户，有解决换其他用户登录时候，需要解决的问换人登录用户的问题
        //>>1：一种是刚刚点开。。刚刚点开的直接读 chat_friend_content_log里面的聊天内容
        //>>2：第二种呢我已经点开当前的界面直接推送到聊天界面
        //>>3: 第三种就是一直没有打开的时候
        //点开一个用户聊天那么当前的窗口就是激活的
        var chat_data_push_list             =   this.commFunctions.parseJson(this.commFunctions.getStoreInfo('chat_friend_content_log'));
        var chat_content_list               =   chat_data_push_list.chat_log_content;
        if(false===chat_data_push_list || 0==chat_content_list.length){
            throw ('抱歉没有任何的聊天信息！');
        }
        var chat_no_open_dom                =   this.query('.'+this.otherEvent.chat_frined_talk+'[mark-name="'+this.nowMessage.userId+'"]');
        if(!chat_data_push_list)
        {
            return false;
        }
        var unread_list                     =     this.underscore.where(chat_content_list,{username: this.nowMessage.username,userId:this.nowMessage.userId,is_read:false});
        var chat_now_client                 =     this.commonGetChatFlag('.chat_board_main');
        console.debug(chat_now_client);
        var unread_box_message              =     chat_no_open_dom.closest('.main_list').find('.message_un_box');
        var date_time                       =     this.commonFromat(parseInt(this.nowMessage.timestamp));
        if( /*需要判断当前是否聊天的回话框
             *是否是自己
             */!this.query('.chat_box_list').data('isActive') || this.nowMessage.username!=chat_now_client){
                if(false===unread_box_message.is(':hidden'))
                {
                    var text   = unread_box_message.text() ;
                    var number = text=='undefined' || text=='' || text==undefined?0:parseInt(text);
                    unread_box_message.text(++number);
                }
                return false;
        }
        //>>1.分为上线的时候立即统计
        //>>2.切花的时候需要统计
        //说明当前的窗口对应的就是当前的聊天的人
        if(/*当前聊天窗口已经激活*/this.nowMessage.username==chat_now_client){
             //自己发送的消息
            var chat_main_content   = '<li class="'+(this.nowMessage.mine?"chat_mine_talk":"")+'">\
                                            <div class="chat_send_user">\
                                             <img class="send_avatar_img" src="/static/images/images.png"/>'+(this.nowMessage.mine?"<cite><i>"+(date_time)+"</i>&nbsp;&nbsp;"+(this.nowMessage.mine?this.nowMessage.myname:this.nowMessage.username)+"</cite>":"<cite>"+(this.nowMessage.mine?this.nowMessage.myname:this.nowMessage.username)+"&nbsp;&nbsp;<i>"+(date_time)+"</i></cite>")+'\
                                            </div>\
                                            <div class="chat_user_text">'+this.nowMessage.content+'</div>\
                                        </li>';
            this.query('.chat_board_main').find('ul').append(chat_main_content);
            //是当前的滚动条一直在下方
            $('.chat_board_main')[0].scrollTop=$('.chat_board_main')[0].scrollHeight;
        }
        //QQ使用的是udp协议效率高一点 tcp效率回慢一些 如果数据不是那么重要。。或者可靠性不是那么高可选择udp
    },
    onChatSuccess:function(message){
         var _frame             = this.query('#'+this.otherEvent.chat_talk_frame)[0];
             _frame.contentWindow.document.body.innerHTML='';
         this.commonPushFriendMessage(message,true,false);
        $('.chat_board_main')[0].scrollTop=$('.chat_board_main')[0].scrollHeight;
    },
    onCreateGroupSuccess:function(msg){
       console.debug(this.commFunctions.parseJson(msg));
    },
    onRequstGroupUserListSuccess:function(msg){
         this.chat_load_index = this.lay.load(1, {
                shade: [0.1,'#fff'] 
        });
    },
    onGroupUserListSuccess:function(msg){
        //关闭当前的load层
        this.lay.close(this.chat_load_index);
        var user_list    = this.commFunctions.parseJson(msg);
        //如果当前是 vue 就好了 没有了mvvm的写起来不方便 html 5的选择器
        //这里其实是不科学的写法正在找补充的办法 可以了解一下Iframe的特性
        if(this.query('#'+this.otherEvent.chat_group_frame).length!=0){
            this.query('#'+this.otherEvent.chat_group_frame).remove();
        }
        this.commonChatGroupDialog(user_list);
        this.query('.icon_list_box').data('up_dowm',true);
        this.initTalkGroupFrame();
        //初始化当前的群聊对话框
    },  //接收群聊消息
    onAcceptGroupMessageSuccess:function(msg){
        try{
            var accept_data   =   this.commFunctions.parseJson(msg);
            //群聊消息接收
            //首先的判断打开的是不是自己的群组聊天
            //>>是  显示在对话框里面
            //>>否  存储在localstorege里面 当前的对话框上面显示未读消息的数量
            if(0===accept_data.length)
            {
                return false;
            }
            this.group_chat_now  = accept_data;
            //显示当前的群组聊天消息 因为初始化的时候都会去调用一次
            this.emitPushGoupChatContent(true);
        }catch(e){
            this.lay.msg(typeof e =='object'?JSON.stringify(e):e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    initTalkGroupFrame:function(){
        var  _groupFrame   = this.query('#'+this.otherEvent.chat_group_frame);//当前聊天的对话框初始化
        _groupFrame        = _groupFrame[0]; //获得原始的frame标签
        _groupFrame.contentWindow.document.designMode='on'; //设置当前的iframe标签的可编辑
        _groupFrame.contentWindow.focus();
        _groupFrame.contentWindow.document.canHaveHTML=true; //设置当前的iframe可以插入当前的html标签
    },
    emitPushGoupChatContent:function(pushMark){
        //首先存储当前的聊天记录 用vue可能更加的简单些
        this.emitPushGroupStock();
        //如果我选择了那么就代表我打开了
        if(this.chat_group_select.group_name===this.group_chat_now.group_name && true===pushMark)
        {
            //此地方写dom操作
            return false;
        }

    },
    emitPushGroupStock:function(){
        try{
            //判断当前消息是否在当前的群组列表里面
            if(0===this.underscore.where(this.group_list,{group_id:this.group_chat_now.group_id}).length)
            {
                return false;
            }
            //排序的话应该是不会
            var stockGroupData   = this.commFunctions.getStoreInfo('group_history_content'),that=this;
            if(!stockGroupData){
                var history_list_group = {content_history_list:[]};
                history_list_group.content_history_list.push(Object.assign({},this.group_chat_now));
                this.commFunctions.setStoreInfo('group_history_content',JSON.stringify(history_list_group));
            }
            stockGroupData   = this.commFunctions.parseJson(this.commFunctions.getStoreInfo('group_history_content'));
            //当天的消息列表
            var bridge_data  = stockGroupData.content_history_list;
            //当前的那个什么
            if(0===bridge_data.length){return false;}
            //取出当前记录查看有多少条;
            if(this.underscore.where(bridge_data,{group_id:this.group_chat_now.group_id}).length>=10){
                //各自分开计算 没有返回 [] 有则返回[object]
                var  wg          =  this.underscore.where(bridge_data,{group_id:this.group_chat_now.group_id});
                //先取出符合条件的
                var  bridge_data =  bridge_data.filter(function(elFilter){
                     return parseInt(elFilter.group_id)==that.group_chat_now.group_id?false:true;
                });
                //首先去除开始的多余的数据只保留10条 先进行降序排序在存储的时候进行降序排序
                wg.sort(function(a,b){
                    var sort_one  = a.timestamp;
                    var sort_two  = b.timestamp;
                    return b.timestamp-a.timestamp;
                });
                wg.length   = 9; //因为下面还要继续添加 保证当前的history 长度为10
                //进行一个升序的排列就行了 自定义排序 
                wg.sort(function(a,b){
                    var sort_one  = a.timestamp;
                    var sort_two  = b.timestamp;
                    return a.timestamp-b.timestamp;
                });
                //将当前的消息push到选好的集合里面
                wg.push(this.group_chat_now);
                //再将整理好的数据在加入到我们的过滤后的数组当中去
                bridge_data      = this.underscore.union(bridge_data,wg);
            }else{
                bridge_data.push(this.group_chat_now);
            }
            //这个只是初步的消息存储。。还的存储当前的最新的聊天记录是吧
            stockGroupData.content_history_list=bridge_data;
            this.commFunctions.setStoreInfo('group_history_content',JSON.stringify(stockGroupData));
      }catch(e){
        this.lay.msg(typeof e==='object'?JSON.stringify(e):e,{time:this.config.tips_second,icon:2});
        return false;
      }
    },
    //当前的服务器发送接口
    emitLoginInterface:function() {
        try {
            var that                    =    this;
            var chat_login_page         =    this.query('.login_page');
            if(0===chat_login_page.length){
                throw '抱歉缺少登录节点';
            }
            var  chat_login_data        =  '';
            chat_login_page.find(':input[type!=button]').each(function(){
                if(true===that.commFunctions.emptyValue(that.query(this).val())){
                    throw  (that.query(this).attr('placeholder'));
                }
                chat_login_data      +=  that.query(this).attr('name')+'='+that.query(this).val()+'&';
            });
            chat_login_data         = chat_login_data+'login_uMask='+this.uMask;
            this.socketIo.emit(this.config.socketEvents.emitEvents.login_emit,chat_login_data);
        }catch (e) {
            this.lay.msg(e, {time: this.config.tips_second, icon:2});
            return false;
        }
    },
    emitRegisterInterface:function() {
        try {
            var that                    =   this;
            var chat_register_page      =   this.query('.register_page');
            if(0===chat_register_page.length){
                throw ('抱歉缺少注册节点');
            }
            var chat_register_data      =   '';
            chat_register_page.find(':input[type!=button]').each(function(){
                if(true==that.commFunctions.emptyValue(that.query(this).val()))
                {
                    throw  (that.query(this).attr('placeholder'));
                }
                if(that.query(this).attr('type')=='radio'){
                    if(false===that.query(this).is(":checked")){
                        return true;
                    }
                }
                chat_register_data+=that.query(this).attr('name')+'='+that.query(this).val()+'&';
            });
            chat_register_data          =   chat_register_data+'register_uMask='+this.uMask;
            this.socketIo.emit(this.config.socketEvents.emitEvents.register_emit,chat_register_data);
        }catch (e){
            this.lay.msg(e, {time: this.config.tips_second, icon:2});
            return false;
        }
    },
    emitChatInterface:function(){
        try{
                 var chat_friend_info   = this.ChatTalkUser;
                 var _frame             = this.query('#'+this.otherEvent.chat_talk_frame)[0];
                 var content            =   _frame.contentWindow.document.body.innerHTML;
                 if(this.commFunctions.emptyValue(content)){
                    throw ('抱歉输入的内容不能为空！');
                 }
                 var chat_param=JSON.stringify({
                       chat_from_name:chat_friend_info.my_name,
                       chat_from_id:chat_friend_info.my_id,
                       chat_message_type:1,
                       chat_to_name:chat_friend_info.friend_name,
                       chat_to_id:chat_friend_info.friend_id,
                       chat_message:content,
                       chat_uMask:this.uMask
                 }); 
                 this.socketIo.emit(this.config.socketEvents.emitEvents.chat_emit,chat_param);
      }catch(e){
        this.lay.msg(e,{time:this.config.tips_second,icon:2});
        return false;
      }
    },
    emitSearchFriend:function(event){
        try {

            var search_friend_name  =   this.query(event).closest('div').find(":input").val();
           /* if( this.search_friend_name===search_friend_name)
            {
                throw ('抱歉输入的好友名称都没有改变！');
            }*/
            this.search_friend_name =   search_friend_name;
            if(true===this.commFunctions.emptyValue(search_friend_name))
            {
                throw  (this.query(event).prev().find(":input").attr('placeholder'));
            }
           if(false===this.commFunctions.getStoreInfo('userInfo'))
           {
               throw  ('已过期抱歉请你登录！');
           }
           var user_param           =   this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo'));
            if(search_friend_name==user_param.name || false==user_param)
            {
                throw ('你自己不能加自己！');
            }
            var  queryString        =   this.commFunctions.requestQueryParam({
                search_friend_name:search_friend_name,
                search_id:user_param.id,
                search_name:user_param.name,
                search_uMask:this.uMask
            });
            this.socketIo.emit(this.config.socketEvents.emitEvents.search_friend_emit,queryString);
            this.use_dom            =   event; //保存当前点击过的dom节点
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    emitAddFriend:function(event){
        try {
            var add_friend_name =this.query(event).closest('div').prev('div').find('.search_line_name').find("span:first").text();
            if(
                true==this.commFunctions.emptyValue(add_friend_name)
            )
            {
                throw ('抱歉数据不合法');
            }
            var add_friend_data = '';
            //设计应该设计成回调函数
            this.query(this.search_user_list).each(function(){
               if(add_friend_name==this.name)
               {
                   add_friend_data  = this;
                   return false;
               }
            });
            var from_user_data      =   this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo'));
            if(false==from_user_data)
            {
                throw ('抱歉超时请您重新登录!');
            }
            var queryString         =   this.commFunctions.requestQueryParam({
                add_id:from_user_data.id,
                add_name:from_user_data.name,
                friend_id:add_friend_data.id,
                friend_name:add_friend_data.name,
                add_uMask:this.uMask
            });
            this.socketIo.emit(this.config.socketEvents.emitEvents.add_friend_emit,queryString);
            this.lay.closeAll();
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    emitAcceptAddFriendRequest:function(type){
        try{
            var accept_info     =   this.commFunctions.getStoreInfo('userInfo');
            if(false===accept_info || false===this.commFunctions.parseJson(accept_info)){
                throw ('抱歉超时请重新登录或注册！');
            }
            accept_info         =   this.commFunctions.parseJson(accept_info);
            var to_chat_id      =   this.query(this.use_dom).attr('mark-class');
            var to_chat_name    =   this.query(this.use_dom).attr('mark-name');
            if(true===this.commFunctions.emptyValue(to_chat_id) || true===this.commFunctions.emptyValue(to_chat_name))
            {
                throw ('抱歉数据不合法');
            }
            var queryString     =   this.commFunctions.requestQueryParam({
                accept_add_friend_request_uMask:this.uMask,
                accept_from_chat_name:accept_info.name,
                accept_from_chat_id:accept_info.id,
                accept_to_chat_name:to_chat_name,
                accept_to_chat_id:to_chat_id,
                accept_chat_type:type
            });
            this.socketIo.emit(this.config.socketEvents.emitEvents.accept_add_friend_request_emit,queryString);
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    emitSearchGroup:function(event){
       try {
           var search_group_name      =   this.query(event).closest('div').find(":input").val();
          /* if(this.search_group_name===search_group_name)
           {
               throw ('输入内容没变化！');
           }
           this.search_group_name   =search_group_name;*/

           if(true===this.commFunctions.emptyValue(search_group_name))
           {
               throw (group_dom.attr('placeholder'));
           }
           var search_group_info    =   this.commFunctions.getStoreInfo('userInfo');
           if(false==search_group_info){
               throw ('抱歉请尝试重新登录！');
           }
           search_group_info        =  this.commFunctions.parseJson(search_group_info);
           var queryString          =  this.commFunctions.requestQueryParam({
               search_group_from_id:search_group_info.id,
               search_group_from_name:search_group_info.name,
               search_group_name:search_group_name,
               search_group_uMask:this.uMask
           });
           /*需要的时候在重置当前的dom节点 this.use_dom=event;*/
           this.use_dom =   event;
           this.socketIo.emit(this.config.socketEvents.emitEvents.search_group_emit,queryString);
       }catch (e){
           this.lay.msg(e,{time:this.config.tips_second,icon:2});
           return false;
       }
    },
    emitJoinGroup:function(event){
        try {
            var apply_join_group_name   = this.query(event).closest('div').prev('div').find('.search_line_name').find("span:first").text();
            if(true===this.commFunctions.emptyValue(apply_join_group_name))
            {
                throw ('抱歉当前组不存在！');
            }
            var apply_join_group_data  ='';
            this.query(this.search_group_list).each(function(){
                if(apply_join_group_name===this.group_name)
                {
                    apply_join_group_data= this;
                    return false;
                }
            });
            var join_group_info     =this.commFunctions.getStoreInfo('userInfo');
            if(false===join_group_info)
            {
                throw ('抱歉账号过期请您登录或者注册');
            }
            join_group_info         =this.commFunctions.parseJson(join_group_info);
            var queryString         =this.commFunctions.requestQueryParam({
                join_group_from_user_name:join_group_info.name,
                join_group_from_user_id:join_group_info.id,
                join_group_name:apply_join_group_data.group_name,
                join_group_id:apply_join_group_data.id,
                join_group_uMask:this.uMask
            });
            this.socketIo.emit(this.config.socketEvents.emitEvents.apply_join_group_emit,queryString);
            this.lay.closeAll();
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    emitJoinGroupRequestIsAgree:function(type){
        try{
            var is_agree_join_group_info        =   this.commFunctions.getStoreInfo('userInfo');
            if(false===is_agree_join_group_info || false==this.commFunctions.parseJson(is_agree_join_group_info))
            {
                throw  ('抱歉超时请重新登录或者注册！');
            }
            var mark_group      = this.query(this.use_dom).attr('mark-group');
            var to_chat_id      = this.query(this.use_dom).attr('mark-class');
            var to_chat_name    = this.query(this.use_dom).attr('mark-name');
            if(
                true===this.commFunctions.emptyValue(mark_group) || 
                true===this.commFunctions.emptyValue(to_chat_id) ||
                true===this.commFunctions.emptyValue(to_chat_name)
              ){
                throw ('抱歉数据不合法！');
               }
            var is_agree_info   =this.commFunctions.parseJson(is_agree_join_group_info);
            var queryString     =this.commFunctions.requestQueryParam({
                isAgree_join_group_from_user_name:is_agree_info.name,
                isAgree_join_group_from_user_id:is_agree_info.id,
                isAgree_join_group_to_user_name:to_chat_name,
                isAgree_join_group_to_user_id:to_chat_id,
                isAgree_join_group_id:mark_group,
                isAgree_join_group_type:type,
                isAgree_join_group_uMask:this.uMask
            });
            this.socketIo.emit(this.config.socketEvents.emitEvents.agree_join_group_emit,queryString);
        }catch (e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    emitUserAddCategory:function(event){
        try {
            var consumer_category_dom = this.query(event).closest('div').find(':input[type!=button]');
            if(0===consumer_category_dom.length)
            {
                throw ('抱歉当前的dom不存在！');
            }
            var consumer_category_data  =consumer_category_dom.val();
           if(true===this.commFunctions.emptyValue(consumer_category_data))
           {
               throw (this.query(consumer_category_dom).attr('placeholder'));
           }
           if(
               false===this.commFunctions.getStoreInfo('userInfo')
               ||
               false===this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo'))
           )
           {
               throw ('抱歉超时请重新登录或注册！');
           }
           var consumer_data_info       =  this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo'));
           var queryString              =  this.commFunctions.requestQueryParam({
               add_cate_user_name:consumer_data_info.name,
               add_cate_user_id:consumer_data_info.id,
               add_cate_name:consumer_category_data,
               add_cate_uMask:this.uMask,
           });
           this.socketIo.emit(this.config.socketEvents.emitEvents.user_add_category_emit,queryString);
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
            return false;
        }

    },
    emitUnreadSingleMessag:function(event){
        try{
            var  unread_info    = this.commFunctions.getStoreInfo('userInfo');
            if(false===unread_info || false===this.commFunctions.parseJson(unread_info))
            {
                throw ('抱歉超时请您重新登录！');
            }
            unread_info         = this.commFunctions.parseJson(unread_info);
            var queryString     = this.commFunctions.requestQueryParam({
                unread_single_id:unread_info.id,
                unread_single_name:unread_info.name,
                unread_single_uMask:this.uMask,
            });
            this.socketIo.emit(this.config.socketEvents.emitEvents.unread_single_messag_emit,queryString);
            this.use_dom   =event;
        }catch(e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    emitRefuseAgree:function(event){
        this.use_dom     =  event;
        var mark_sheet   =  this.query(event).attr('mark-shit');
        switch(mark_sheet){
            case  this.otherEvent.chat_agree_add_freind :
            this.emitAcceptAddFriendRequest('agree');
            break;
            case this.otherEvent.chat_refuse_add_friend :
            this.emitAcceptAddFriendRequest('disagree');
            break;
            case this.otherEvent.chat_agree_join_group :
            this.emitJoinGroupRequestIsAgree('agree');
            break;
            case this.otherEvent.chat_refuse_join_group :
            this.emitJoinGroupRequestIsAgree('disagree');
            break;
        }
    },
    emitChatClientOpen:function(event){
        try{ 
             this.use_dom     = event;
             var that         = this;
             var mark_name    = parseInt(this.query(event).attr('mark-name'));
             //只要点击就会打开一个聊天的窗口
             var chat_to_talk = {};
             this.underscore.each(this.frined_list,function(el,index) {
                 chat_to_talk     = that.underscore.findWhere(el,{friend_id:mark_name});
                 if(!that.underscore.findWhere(that.chatFriendTalkList,{friend_id:mark_name}))
                 {
                    //做聊天历史记录的 这个没有做数据持久化也可以写接口做数据redis存储 for of  break
                    that.chatFriendTalkList.push(chat_to_talk);
                 }
                 //没有找到
                if('undefined'==chat_to_talk){ 
                    return false;
                }else{
                     chat_to_talk     = that.underscore.findWhere(el,{friend_id:mark_name});
                     that.ChatTalkUser= that.underscore.findWhere(el,{friend_id:mark_name});
                     if(that.ChatTalkUser.of_list){
                        that.ChatTalkUser.of_list.forEach(function(elem){
                             //>>首先同步到本地  直接发送
                             that.commonPushFriendMessage(elem,false,true);
                             //这里需要吧本地的数据给清空
                        });
                        that.emitSyncUnreadMessage(JSON.stringify({
                           unread_from_name:chat_to_talk.friend_name,
                           unread_to_name:that.mineInfo.name,
                           unread_uMask:that.uMask,
                        }));
                     }
                     //清空当前的未读消息
                     that.frined_list[index].of_list = [];
                     //当前的消息盒子
                     that.query(that.use_dom).siblings('.inf_box').find('.message_un_box').text('');
                }
            });
            if('undefined'==chat_to_talk || 0===chat_to_talk.length)
            {
                throw ('您选的聊天对象不存在！');
            }
            //sync_store_unread_emit
            //clone继承 或者是属性继承
            //判断是否激活
            if(true===this.query('.chat_box_list').data('isActive')){
                this.commonBufferFriendList('.chat_friend_list');
                this.commonTileBuffer('.chat_board_title')
                this.commonSetChatFlag('.chat_board_main');
                this.commonGetList();
                return false;
            }

            //当前的层只弹出一次
            var layOptions   = {
                          type: 1,
                          area: ['50%','76%'],
                          shade: 0 ,
                          maxmin: true ,
                          anim: 1 ,
                          title:'聊天列表',
            }
            var chat_body         =   this.commonCreateChatBody();
            layOptions.content    =   chat_body[0].outerHTML;
            this.commonDialog(layOptions);
            //设置活动属性 也可以判断 .chat_box_list 的是否存在
            this.query('.chat_box_list').data('isActive',true);
            //设置当前的聊天窗口标识
            this.commonSetChatFlag('.chat_board_main');
            //初始化聊天iframe接口
            this.initTalkFrame();
            $('.chat_board_main')[0].scrollTop=$('.chat_board_main')[0].scrollHeight;
        }catch(e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    emitSyncUnreadMessage:function(msg){
        //直接把redis里面异步数据持久化db
        this.socketIo.emit(this.config.socketEvents.emitEvents.sync_store_unread_emit,msg);
    },
    emitCreateGroup:function($event){
       try{

              var user_info   = this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo')),that=this;
              if(false===user_info)
              {
                throw ('抱歉登录超时！');
              };
              var options    ={
                type:1,
                title:false,
                area:['300px','300px'],
                shade:0,
                maxmin:false,
                anim:1,
                closeBtn: false,
                btn:['立马创建','暂不创建'],
              };
              //创建聊天组
              options.content  = "<div style='width:100%';height:300px;><label>请输入当前的名字</label><input name='group' placeholder='请输入创建群的名称' ></div>",
              options.yes=function(index,layereo){
                try{
                        var dialog_body   =   layereo[0];
                        var input         =   that.query(dialog_body).find('input');
                        if(0===input.length){
                            throw ('抱歉我可能要被杀来祭天了！！');
                        }
                        var  group_name   =     that.query(input).val();
                        if(true===that.commFunctions.emptyValue(group_name))
                        {
                              throw ('抱歉组名不能为空！');
                        }
                        var queryString=JSON.stringify({
                         create_user_name:user_info.name,
                         create_user_id:user_info.id,
                         create_group_name:input.val(),
                         create_group_uMask:that.uMask,
                        });
                        that.socketIo.emit(that.config.socketEvents.emitEvents.create_group_emit,queryString);
                }catch(e){
                     that.lay.msg(JSON.stringify(e),{time:that.config.tips_second,icon:2});
                }
              }
              this.commonDialog(options);
      }catch(e){
        this.lay.msg(JSON.stringify(e),{time:this.config.tips_second,icon:2});
        return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
      }
    },
    emitGroupChat:function(use_dom){
      try{
           var group_id_data      =  this.query(use_dom).data('group');
           this.chat_group_select =  this.underscore.findWhere(this.group_list,{group_id:group_id_data});
           
           var userInfo           = this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo'));
           if(false===userInfo)
           {
                  throw  ('抱歉登录超时,请重新登录');  
           }
           var queryString        =  JSON.stringify({
                member_group_user_name:userInfo.name,
                member_group_user_id:userInfo.id,
                member_group_name:this.chat_group_select.group_name,
                member_group_id:this.chat_group_select.group_id,
                member_group_uMask:this.uMask,
           });
           this.socketIo.emit(this.config.socketEvents.emitEvents.get_group_members_emit,queryString);
       }catch(e){
            this.lay.msg( typeof e  ==='object'?JSON.stringify(e):e,{time:this.config.tips_second,icon:2});
            return false;
       }
    },
    emitCahtGroupMessage:function(event){
        try{
         var   _GroupFrame     =   this.query('#'+this.otherEvent.chat_group_frame)[0];
         var   _content        =_GroupFrame.contentWindow.document.body.innerHTML;
         if(true==this.commFunctions.emptyValue(_content)){
            throw ('聊天内容不能为空！');
         }
         var info          = this.commFunctions.parseJson(this.commFunctions.getStoreInfo('userInfo'));
         if(false===info){
            throw  '付不请你重新返回登录';
         }
         var queryString   = JSON.stringify({
            group_chat_user_name:info.name,
            group_chat_user_id:info.id,
            group_chat_group_name:this.chat_group_select.group_name,
            group_chat_group_id:this.chat_group_select.group_id,
            group_chat_group_content:_content,
            group_chat_group_uMask:this.uMask,
         });
         //发送当前的群聊消息
         this.socketIo.emit(this.config.socketEvents.emitEvents.group_chat_emit,queryString);
        }catch(e){
            this.lay.msg(typeof e =="object"?JSON.stringify(e):e,{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    initTalkFrame:function(){
        var _frame  = this.query('#'+this.otherEvent.chat_talk_frame);
        _frame      = _frame[0];
        _frame.contentWindow.document.designMode='on'; //设置当前的iframe标签的可编辑
        _frame.contentWindow.focus();
        _frame.contentWindow.document.canHaveHTML=true; //设置当前的iframe可以插入当前的html标签
    },
    commonCreateChatBody:function(icon_str,name_str){
        var chat_box_list        =   this.query('<div class="chat_box_list"></div>');
        var chat_friend_list     =   this.commonCReateChatFriendList();
        var chat_friend_board    =   this.commonCreateChatBorad();
        var all_chat_board       =   chat_friend_list[0].outerHTML+chat_friend_board[0].outerHTML;
        this.query(chat_box_list).html(all_chat_board);
        return chat_box_list;
    },
    commonCReateChatFriendList:function(){

        var  friend_list_body   =this.query('<div class="chat_friend_list">\
                                                <ul class="chat_friend_more">\
                                                </ul>\
                                        </div>');
        var friend_list_body =this.commonBufferFriendList(friend_list_body);
        return friend_list_body;
    },
    commonBufferFriendList:function(body){
             var that           = this;
             var friend_html    ='';
             var friend_list    = this.chatFriendTalkList.forEach(function(el){
                    var is_active  = false;
                    if(that.ChatTalkUser===el){is_active=true;}
                    friend_html+='<li class="chat_friend  '+(is_active?'chat_active':'')+'" mark-name="'+el.friend_id+'"><img class="friend_avatar" src="/static/images/images.png"/><span>'+el.friend_name+'</span></li>';
             });
             this.query(body).find('ul').html(friend_html);
             return body;
    },
    commonCreateChatBorad:function(){
      var chat_board          =  this.query('<div class="chat_board"></div>');
      var char_board_title    =  this.commonCreateChatBoradTitle();
      var chat_board_main     =  this.commonCreateChatBoradMain();
      var chat_border_content =char_board_title[0].outerHTML+chat_board_main;
      this.query(chat_board).html(chat_border_content);
      return chat_board;
    },
    commonCreateChatBoradTitle:function(){
         var chat_board_title= this.query('<div class="chat_board_title">\
                             <div class="chat_title_header">\
                                <img class="chat_title_avatar" src="/static/images/images.png"><span></span>\
                             </div>\
                            </div>');
       var   chat_board_title     =  this.commonTileBuffer(chat_board_title);
       return  chat_board_title;
    },
    commonTileBuffer:function(border_title){
        this.query(border_title).find('span').text(this.ChatTalkUser.friend_name);
        return border_title;
    },
    commonCreateChatBoradMain:function(mian_data){
        var list_history  = this.commonGetList();
        var chat_mian_data= this.query('<div class="chat_board_main">\
                                       <ul class="chat_accept_message" title="鼠标上下滑动查看消息">\
                                       '+list_history+'\
                                     </ul>\
                                </div>');
        //给聊天窗口设置聊天标识;
        var chat_main_icon       = this.commonCreateChatSendIcon();
        var chat_main_send_board = this.commonCreateChatSendBoard();
       return chat_mian_data[0].outerHTML+chat_main_icon[0].outerHTML+chat_main_send_board[0].outerHTML;
    },
    commonCreateChatSendIcon:function(){
         var chat_icon=this.query('<div class="chat_board_icon"><div class="chat_board_icon_list"><span class="img_btn"><i class="layui-icon">&#xe60d;</i></span> <span class="img_btn"><i class="layui-icon">&#xe61d;</i></span></div></div>');
         return chat_icon;
    },
    commonCreateChatSendBoard:function(){
        var chat_send_board  = this.query('<div class="chat_board_send">\
                                    <div class="chat_message_input">\
                                          <iframe frameborder="1" src="javascript:;" class="cr_inp" id="editor"></iframe>\
                                    </div>\
                                    <div class="chat_message_send"><div class="send_btn"><span class="close_frame">关闭</span><span class="send_message">发送</span></div></div>\
                               </div>');
       return chat_send_board;
    },
    commonSetChatFlag:function(chat_mine){
        this.query(chat_mine).data('isChatNow',this.ChatTalkUser.friend_name);
        return chat_mine;
    },
    commonGetChatFlag:function(chat_mine){
        return  this.query(chat_mine).data('isChatNow');
    },
    //当前的公共接口
    commonJumpRegister:function(event) {  //前往注册的接口
        try {
            window.location.href    =   this.otherUri.registerJumpUri
        }catch (e) {
            this.lay.msg(e, {time: this.config.tips_second, icon:2});
            return false;
        }
    },
    commonJumpLogin:function(){  //返回登录的接口
        try {
            window.location.href    =   this.otherUri.backJumpUri;
        }catch (e) {
            this.lay.msg(e, {time: this.config.tips_second, icon:2});
            return false;
        }
    },
    commonChatLogSplit:function(){

    },
    commonDialog:function(options){
        this.lay.closeAll();
        return   this.lay.open(options);
    },
    commonFromat:function(timestamp){
         var return_date   = new Date((timestamp*1000));
         var date_return=return_date.getFullYear()+'-'
         +(return_date.getMonth()+1)+'-'
         +return_date.getDate()+' '
         +return_date.getHours()+':'
         +return_date.getMinutes()+':'
         +return_date.getSeconds();
         return date_return;
    },
    commonGetList:function(){
        try{
            var that                =this;
            var name                = this.ChatTalkUser.friend_name;
            var chat_list_content   = this.commFunctions.getStoreInfo('chat_friend_content_log');
            if(false==chat_list_content){return false}
            var chat_history        = this.commFunctions.parseJson(chat_list_content);
            var list_talk           = this.underscore.where(chat_history.chat_log_content,{username:name});
            var chat_main_content    = '';
            list_talk.forEach(function(el,index){
                date_time                       =     that.commonFromat(parseInt(el.timestamp));
                chat_main_content   += '<li class="'+(el.mine?"chat_mine_talk":"")+'">\
                                            <div class="chat_send_user">\
                                             <img class="send_avatar_img" src="/static/images/images.png"/>'+(el.mine?"<cite><i>"+(date_time)+"</i>&nbsp;&nbsp;"+(el.mine?el.myname:el.username)+"</cite>":"<cite>"+(el.mine?el.myname:el.username)+"&nbsp;&nbsp;<i>"+(date_time)+"</i></cite>")+'\
                                            </div>\
                                            <div class="chat_user_text">'+el.content+'</div>\
                                        </li>';
             });
            if(true===this.query('.chat_box_list').data('isActive')){
                 this.query('.chat_board_main').find('ul').html(chat_main_content);
                 //是当前的滚动条一直在下方
                $('.chat_board_main')[0].scrollTop=$('.chat_board_main')[0].scrollHeight;
            }else{
                return chat_main_content;
            }
        }catch(e){
            this.lay.msg(JSON.stringify(e),{time:this.config.tips_second,icon:2});
            return false;
        }
    },
    commonPushFriendMessage:function(msg,is_min,read_even){
        try{
            var that                = this,read_even_data=read_even===false ?false:read_even; 
            //直接同步当前的消息到local里面
            var chat_log_data       = this.commFunctions.getStoreInfo('chat_friend_content_log');
            //怎么达到当前的消息未读数量最准确？？？
            if(!chat_log_data || chat_log_data==null)
            {
                var chat_log = {
                    chat_log_content:[],
                };
                chat_log_data      =JSON.stringify(chat_log);
                this.commFunctions.setStoreInfo('chat_friend_content_log',JSON.stringify(chat_log));
            }
            var store_info   = this.commFunctions.parseJson(msg);
            //>>1、需要判断的是当前的窗口是否激活   
            var read_type    = true;
            //>>2、判断当前的给我的什么消息是否是当前的我激活的这个人
            if((!this.commonGetChatFlag('.chat_board_main') && 
                /*不需要比较类型*/this.commonGetChatFlag('.chat_board_main')===store_info.chat_to_name
               )|| read_even_data===true
              )
            {
                read_type    = true;
            }
            //存储当前的消息 但是有个问题是当前的如果换了用户该怎么处理
            var content_log_person =  {  //这个是接收的接口那么当前的发送接口也是一样的需要该方法
                type:'friend', //是朋友和朋友的点对点聊天
                username:store_info.chat_to_name?store_info.chat_to_name:store_info.from_chat_name, //对方发给我的昵称
                userId:store_info.chat_to_id?store_info.chat_to_id:store_info.from_chat_id, //对方发给我的消息id
                myname:store_info.chat_from_name?store_info.chat_from_name:store_info.to_chat_name,//自己的名称
                mine:is_min,   //标识是否是我自己
                content:store_info.chat_message?store_info.chat_message:store_info.message,
                is_read:read_type, //当前是否已经读取了消息
                timestamp:store_info.timestamp //当前发送的时间戳
            };
            console.debug(content_log_person);
            //当前接收和发送的消息
            this.nowMessage           =  content_log_person;
            //>>点击可查看当前的历史记录
            //>>方便筛选 用我的underscore 或者可以用我们的lodash做我们的历史记录的筛选
            var  chat_prepare_data    =  this.commFunctions.parseJson(chat_log_data);
            //>>1.如果当前刚刚点开当前的有未读消息的话那么直接查询数据库的未读消息加以显示。。
            //>>2.如果点击之后没有未读消息的话那么就直接读取当前的前端的历史记录
           var hastory_log_list      =  this.underscore.where(chat_prepare_data.chat_log_content,{username: this.nowMessage.username,userId:this.nowMessage.userId});
           //只存储20条历史记录在本地。。其他的记录直接打开新的页面读取
          /* if(hastory_log_list.length>10){   //储存当前的10条他与我的聊天历史记录*/
           var  filter_data  = []; //因为每次来都会置空
           if(hastory_log_list.length>=10){  
                //先过滤当前的不是当前聊天用户的所有聊天记录
                filter_data  = chat_prepare_data.chat_log_content.filter(function(elem){
                    return   elem.username!=that.nowMessage.username;
                });
                var  silce_number    = parseInt(hastory_log_list.length)-10
                hastory_log_list     = hastory_log_list.slice(silce_number+1, hastory_log_list.length);
                hastory_log_list.push(content_log_person);
                filter_data          = this.query.merge(filter_data, hastory_log_list);
            }
            //数组是对象是应用复值的除了常见类型函数只能改变不能重写
            if(filter_data.length===0){
                  chat_prepare_data.chat_log_content.push(content_log_person);
            }else{
                chat_prepare_data.chat_log_content = filter_data;
            }
            //保持当前的消息条数......以免localstorege爆仓
            console.debug(chat_prepare_data);
            var  store_friend_message =  JSON.stringify(chat_prepare_data);
            this.commFunctions.setStoreInfo('chat_friend_content_log',store_friend_message);
            //>>调用当前的接口直接推送到当前的聊天界面 为每个注册回调函数和这个差不多啦 还会在自己发的消息接口当中写上当前的该 时间问题就不在维护
            //>>主要是当前的思路才是最重要的
            //如果当前点击的是切换的那么就不做数量统计。。。如果做得是当前的 自动触发的时候就会是当前的聊的实时消息结果
            if(true===read_even_data){return false;}
             this.is_min_type        =is_min;
            this.onPushMessage();
        }catch(e){
            this.lay.msg(JSON.stringify(e),{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    commonChatGroupDialog:function(user_list_data){

           var user_list_collection ='';
           this.underscore.each(user_list_data,function(el, index) {
               user_list_collection+='<div class="icon_list" data-id="'+(el.user_id)+'" data-name="'+(el.user_name)+'">\
                                <div class="icon_img"><img src="'+(el.avatar==null || el.avatar=="undefined"?"/static/images/images.png":el.avatar )+'" width="500" height="500" /></div>\
                                <div class="icon_inf">'+(el.user_name)+'</div>\
                               </div>';
           });
           var groupChatDialog  = '<div class="b_box">\
            <div class="b_box_r">\
                <div class="r_title">\
                    <div class="rt_name">\
                        <div class="rtm_img"><img src="/static/images/images.png" width="500" height="500" /></div>\
                        <div class="rtm_inf">'+(this.chat_group_select.group_name)+'</div>\
                        <div class="rtm_num">'+(this.chat_group_select.member_total)+'人</div>\
                        <div class="rtm_img1 swiper_dom"><img src="/static/images/img11.jpg" width="30" height="30" /></div>\
                    </div>\
                    <div class="icon_list_box" style="display:none">\
                    '+user_list_collection+'\
                    </div>\
                </div>\
                <div class="right_cont">\
                </div>\
                <div class="cr_upload">\
                    <div class="up1"></div>\
                    <div class="up2"></div>\
                </div>\
               <iframe frameborder="1" src="javascript:void(0);" class="cr_inp" id="editor_group"></iframe>\
                <div class="cr_but_b">\
                    <input name="" type="button" class="cr_but send_group_step" value="设置" />\
                    <input name="" type="button" class="cr_but send_group" value="发送" />\
                </div>\
            </div>\
        </div>'
     this.dialog_options={
          type: 1,
          area: ['625px', '680px'],
          title: '已选择'+this.chat_group_select.group_name+'群',
          shade: 0,
          maxmin: true ,
          anim: 1,
          content: groupChatDialog
        } //频繁的弹出会话框是否会增加前端的开销等等
        this.dialog_index=this.commonDialog(this.dialog_options);
    },
    TabSwitch:function(event,dom_class){
        try{
            var dom_this        =this.query(event),that=this;
            dom_this.siblings('.'+dom_class).removeClass('hover');
            var mark_step       =   dom_this.addClass('hover').attr('mark-step');
            //没有vue的效果后面可改成vue版本的设置成公共的components{} 没有es6写法简洁
            this.query('.main_box').each(function(){
                if((mark_step+"_list")===that.query(this).attr('mark-step'))
                {
                    that.query(this).removeClass('switch_tab');
                    that.query(this).siblings('.main_box').addClass('switch_tab');
                }
            });
        }catch (e){
            this.lay.msg(e,{time:this.config.tips_second,icon:2});
        }

    },
    searchFriendGroupShow:function()
    {
        if(true===this.query('.search_friends_group').closest('div').is(':hidden'))
        {
            this.query('.search_friends_group').closest('div').show();
        }
    },
    searchDis:function(event)
    {
        try{
           switch (this.search_type)
           {
               case this.otherEvent.chat_add_friend:this.emitSearchFriend(event);
                   break;
               case this.otherEvent.chat_add_group:this.emitSearchGroup(event);
                   break;
           }
        }catch (e){
            this.lay.msg(e,{icon:2,time:this.config.tips_second});
            return false;
        }
    },
    GetMessageNum:function(){
      try {
          message_text=this.unread_message = this.query('.is_show_message').text();
          if (true === this.commFunctions.emptyValue(message_text) || 0==message_text) {
              this.query('.is_show_message').hide();
          } else {
              this.query('.is_show_message').show();
          }
      }catch (e){
          this.lay.msg(e,{time:this.config.tips_second,icon:2})
      }
      return this;
    }, //当前群组列表收缩js
    commonSwiperAction:function(event){
         if(!this.query('.icon_list_box').data('up_dowm'))
         {
            this.query('.icon_list_box').slideDown(400,function(el,test){
                //下滑到最后时回调
            });
            this.query('.icon_list_box').data('up_dowm',true);
         }else{
            this.query('.icon_list_box').slideUp(400);
            this.query('.icon_list_box').data('up_dowm',false);
         }
    },
};